package com.ruoyi.system.controller.basic;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.PageInfo;
import com.ruoyi.system.utils.MyPageUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.db.basic.BasicCargoTypes;
import com.ruoyi.system.service.IBasicCargoTypesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 货物类型Controller
 *
 * @author ruoyi
 * @date 2023-07-25
 */
@RestController
@RequestMapping("/basic/types")
public class BasicCargoTypesController extends BaseController
{
    @Autowired
    private IBasicCargoTypesService basicCargoTypesService;

    /**
     * 查询货物类型列表
     */
    @PreAuthorize("@ss.hasPermi('basic:types:list')")
    @GetMapping("/list")
    public PageInfo<BasicCargoTypes> list(BasicCargoTypes basicCargoTypes)
    {

        List<BasicCargoTypes> list = basicCargoTypesService.selectBasicCargoTypesList(basicCargoTypes);
        return MyPageUtils.startPage(list);
    }

    /**
     * 导出货物类型列表
     */
    @PreAuthorize("@ss.hasPermi('basic:types:export')")
    @Log(title = "货物类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasicCargoTypes basicCargoTypes)
    {
        List<BasicCargoTypes> list = basicCargoTypesService.selectBasicCargoTypesList(basicCargoTypes);
        ExcelUtil<BasicCargoTypes> util = new ExcelUtil<BasicCargoTypes>(BasicCargoTypes.class);
        util.exportExcel(response, list, "货物类型数据");
    }

    /**
     * 获取货物类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:types:query')")
    @GetMapping(value = "/{cargoTypeId}")
    public AjaxResult getInfo(@PathVariable("cargoTypeId") Integer cargoTypeId)
    {
        return success(basicCargoTypesService.selectBasicCargoTypesByCargoTypeId(cargoTypeId));
    }

    /**
     * 新增货物类型
     */
    @PreAuthorize("@ss.hasPermi('basic:types:add')")
    @Log(title = "货物类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasicCargoTypes basicCargoTypes)
    {
        return toAjax(basicCargoTypesService.insertBasicCargoTypes(basicCargoTypes));
    }

    /**
     * 修改货物类型
     */
    @PreAuthorize("@ss.hasPermi('basic:types:edit')")
    @Log(title = "货物类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasicCargoTypes basicCargoTypes)
    {
        return toAjax(basicCargoTypesService.updateBasicCargoTypes(basicCargoTypes));
    }

    /**
     * 删除货物类型
     */
    @PreAuthorize("@ss.hasPermi('basic:types:remove')")
    @Log(title = "货物类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{cargoTypeIds}")
    public AjaxResult remove(@PathVariable Integer[] cargoTypeIds)
    {
        return toAjax(basicCargoTypesService.deleteBasicCargoTypesByCargoTypeIds(cargoTypeIds));
    }
}
